package com.ess.project.examine.grade.controller;

import com.ess.framework.aspectj.lang.annotation.Log;
import com.ess.framework.aspectj.lang.enums.BusinessType;
import com.ess.framework.web.controller.BaseController;
import com.ess.framework.web.domain.AjaxResult;
import com.ess.framework.web.page.TableDataInfo;
import com.ess.project.examine.grade.domain.ExamineGradeEntity;
import com.ess.project.examine.grade.service.IGradeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * @Description: 考核成绩管理
 * @Date: Created in 2:38 下午 2021/3/6
 * @Author: daihui
 * @Modified By:
 */
@Controller
@RequestMapping("/examine/grade")
public class GradeController extends BaseController {

    private String prefix = "examine/grade";


    @Autowired
    private IGradeService gradeService;


    @RequiresPermissions("examine:grade:view")
    @GetMapping()
    public String grade() {
        return prefix + "/grade";
    }

    @RequiresPermissions("examine:grade:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamineGradeEntity grade) {
        startPage();
        List<ExamineGradeEntity> list = gradeService.selectGradeList(grade);
        return getDataTable(list);
    }

    @Log(title = "考核成绩管理", businessType = BusinessType.EXPORT)
    @RequiresPermissions("examine:grade:export")
    @GetMapping("/export")
    @ResponseBody
    public void downloadExportExamExcel(String personnelCategory, String examineTime, HttpServletResponse response) {
        gradeService.export(personnelCategory, examineTime, response);
    }

    /**
     * 修改考核成绩
     */
    @GetMapping("/edit/{gradeId}")
    public String edit(@PathVariable("gradeId") Integer gradeId, ModelMap mmap) {
        ExamineGradeEntity grade = gradeService.selectRecordById(gradeId);
        mmap.put("grade", grade);
        return prefix + "/edit";
    }

    /**
     * 修改保存考核成绩
     */
    @RequiresPermissions("examine:grade:edit")
    @Log(title = "考核成绩管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated ExamineGradeEntity grade) {
        return toAjax(gradeService.updateGrade(grade));
    }

    @RequiresPermissions("examine:grade:remove")
    @Log(title = "考核成绩管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(gradeService.deleteGradeByIds(ids));
    }

    /**
     * 各类人员对比
     * @param examTime 考核时间
     * @return
     * @author qlq
     * 2021-04-12
     */
    @PostMapping("/getChartsDataForGlrycjdb")
    @ResponseBody
    public Map<String,Object> getChartsDataForGlrycjdb(String examTime) {
        return gradeService.getChartsDataForGlrycjdb(examTime);
    }

    /**
     * 根据人员姓名获取人员成绩并按时间正序排序
     * @param examPersonnel 人员姓名
     * @return
     * @author qlq
     * 2021-04-12
     */
    @PostMapping("/getGradesByPersonnel")
    @ResponseBody
    public Map<String,Object> getGradesByPersonnel(String examPersonnel,String examTime) {
        return gradeService.getGradesByPersonnel(examPersonnel,examTime);
    }

    /**
     * 整体人员对比
     * @return
     * @author qlq
     * 2021-04-12
     */
    @PostMapping("/getChartsDataForZtcjdb")
    @ResponseBody
    public Map<String,Object> getChartsDataForZtcjdb() {
        return gradeService.getChartsDataForZtcjdb();
    }

    /**
     * 获取某一类别下的人员列表
     * @return
     * @author qlq
     * 2021-04-13
     */
    @PostMapping("/getAllPerson")
    @ResponseBody
    public List<ExamineGradeEntity> getAllPerson(String personnelCategory) {
        return gradeService.getAllPerson(personnelCategory);
    }

    /**
     * 单科成绩对比
     * @return
     * @author qlq
     * 2021-04-13
     */
    @PostMapping("/getDkcjdb")
    @ResponseBody
    public Map<String,Object> getDkcjdb(String dkcjdbPersonnelCategory, String dkcjdbPersonName, String khkm) {
        String[] names = dkcjdbPersonName.split(",");
        Map<String,Object> ret = gradeService.getDkcjdb(dkcjdbPersonnelCategory,names,khkm);
        return ret;
    }

}
